/**
 * 关注列表
 * @author
 * @date 2012-11-20
 */

var colNames = ['', 'id','照片', '姓名','关注数量','粉丝数量'];

/**
 * colModel 显示列的属性
 *
 * @type {Object}
 */
var colModel = [
	{ name:'first', index:'first', width:"100%", align:"center" },
	{ name:'id',index:'id', hidden:true }, 
	{ name:'portrait',index:'portrait', hidden:true }, 
	{ name:'nickname',index:'nickname', hidden:true }, 
	{ name:'careCount',index:'careCount', hidden:true },  
	{ name:'fansCount',index:'fansCount', hidden:true }
];

/**
 * rowNum 想要显示的数据行数
 *
 * @type {Number}
 */

var rowNum = 10;

/**
 * total_last 用于判定表格的总页码是否发生了改变
 *
 * @type {Number}
 */

var total_last = 0;

/**
 * loadDataSuccess 判定是否成功加载完数据
 *
 * @type {Boolean}
 */

var loadDataSuccess = false;

$( "#care-table" ).jqGrid({
	url:'../user/getAllMyIdols.html',
	datatype:"json",
	mtype: "POST",
//	datatype: "local",
//	data: local_data,
	height: "auto",
	autowidth: true,
	colNames: colNames, 
	colModel: colModel,
	rowNum: rowNum, 
	viewrecords: true,
	emptyrecords : '赶紧添加你要关注的人吧',
	pager: 'carepager', 
	jsonReader: {
		root: "result",
		page: "page",
		total: "total",
		records: "records",
		repeatitems: false,
		cell: "cell",
		id: "id"
	},
	
	gridComplete:function() {
		// 取消外边框
		$( "#gbox_care-table" ).css( "border", "none" );
		
		// 隐藏表头
		$( "#gview_care-table .ui-jqgrid-hdiv" ).css( "display", "none" );

		// 取消列间的分界限
		$( "#gview_care-table .ui-jqgrid-bdiv td" ).css( "border-right-style", "none" );

		// 改变底边框样式
		$( "#gview_care-table .ui-jqgrid-bdiv tr:not(:first-child) td" ).css( "border-bottom", "1px solid #E5E5E5" );
		
		// 取消最后一行的底边框
		$( "#gview_care-table .ui-jqgrid-bdiv tr:last-child td" ).css( "border-bottom-style", "none" );
		
		// 设置表格行高
		//$( "#gview_care-table .ui-jqgrid-bdiv tr:gt(0)" ).css( "height", "110px" );

		/**
		 * IDs 获取当前页所有数据的id
		 *
		 * @type {Object}
		 */

		var IDs = $( "#care-table" ).jqGrid( "getDataIDs" );
		if(IDs.length==0){
			$("#carepager_center").hide();
			$(".ui-paging-info").css("text-align","left");
			$(".ui-paging-info").css("font-size","15px");
			$(".ui-jqgrid-view").css("height","60px");
		}
		
		for (var i=0; i < IDs.length; i++) {

			/**
			 * everyRowData 根据某一行数据的id获取该数据所有信息
			 *
			 * @type {Object}
			 */

			var everyRowData = $( "#care-table" ).jqGrid( "getRowData", IDs[i] );
			
			// 关注者信息
			metadata = '<div class="model">' + 
							'<div class="photo">' + '<img src="../' + everyRowData.portrait + '"/>' + '</div>' +
							'<div class="message">' +
								'<p>' + '<span class="p-name"><a href="../user/other.html?otherId='+everyRowData.id+'" target="_blank" >' + everyRowData.nickname +'</a>'+
									'<img src="../images/relationship/man.png"/></span>' +
								'</p>' +
								'<p>' +
									' <span>关注<a>' + everyRowData.careCount + '</span><span style="color:#e0e0e0;">|</span>' +
									' <span>粉丝<a>' + everyRowData.fansCount + '</span><span style="color:#e0e0e0;">|</span>' +
								'</p>' +
							'</div>' +
							'<div class="operate"><input type="button" onclick="cancelcare('+everyRowData.id+')" value="取消关注"/></div>' +
						'</div>';	
							 
	       
			$( "#care-table" ).jqGrid( 'setRowData', IDs[i], { first: metadata } );
			// 取消提示信息
			$( ".metadata" ).parent("td").attr("title","");
	
        }		
	},
	onSelectRow: function(rowid) {
		//alert("丫的，跳入个人首页!");
	}
	/*
	//双击该行进入信息详情页
	ondblClickRow: function(rowid) {
	}
	*/
});
function cancelcare(id){
	$.ajax({
		url : '../user/deleteIdol.html',
		data : "idolId="+id,
		type : 'post',
		dataType : 'json',
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(result) {
			if(result==true){
				alert("取消成功");
				location.replace(location.href);
			}
		},

		error : function() {
			alert("连接服务器出错");
		}
	});
}


